<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">租金信息</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="承租人:">
                        <div style="width:190px">
                            <el-input v-model="form.czr" placeholder="请输入承租人" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width:190px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width:190px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="产权单位:">
                        <div style="width:190px">
                            <el-input v-model="form.cqdw" placeholder="请输入产权单位" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="预转已:">
                        <el-select v-model="form.yzy" placeholder="请选择是否可执行预转已" clearable @change="onchangeradio">
                            <el-option v-for="item in yzylist" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-button type="primary" @click="yzyclick" class="searchcolor" style="margin-bottom: 10px;">预转已</el-button>
<!-- max-height="330" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                    :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor"
                @selection-change="handleSelectionChange" border :max-height="maxHeight">
                <el-table-column type="selection" width="55" :selectable="selectable">
                </el-table-column>
                <el-table-column prop="htbh" label="合同编号" align="center" fixed width="160"> </el-table-column>
                <el-table-column prop="dabh" label="档案编号" align="center" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center" width="200" :show-overflow-tooltip="true"> </el-table-column>
                <el-table-column prop="czr" label="承租单位" align="center" width="280"> </el-table-column>
                <el-table-column prop="zjdj" label="租金单价" align="center"> </el-table-column>
                <el-table-column prop="qdsj" label="签订时间" align="center" width="120">
                    <template slot-scope="scope">
                        {{ scope.row.qdsj ? scope.row.qdsj.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column prop="zlqssj" label="起租时间" align="center" width="120">
                    <template slot-scope="scope">
                        {{ scope.row.zlqssj ? scope.row.zlqssj.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
                <el-table-column prop="zldqsj" label="到期时间" align="center" width="120">
                    <template slot-scope="scope">
                        {{ scope.row.zldqsj ? scope.row.zldqsj.split(' ')[0] : '' }}
                    </template>
                </el-table-column>

                <!-- <el-table-column prop="fwdz" label="房屋地址" align="center">
                    <template slot-scope="scope">
                        <span style="font-weight: 700;color: #409ee1;">
                            {{ scope.row.fwdz }}
                        </span>
                    </template>
                </el-table-column> -->
                <el-table-column prop="ysje" label="预收金额" align="center"> </el-table-column>
                <el-table-column prop="dqje" label="当欠金额" align="center"> </el-table-column>
                <el-table-column prop="jqje" label="旧欠金额" align="center"> </el-table-column>
                <el-table-column label="操作" width="100" align="center" fixed="right">
                    <template slot-scope="scope">

                        <router-link :to="{ name: 'wtzjgladd', query: { id: scope.row.id, signid: scope.row.signid } }">
                            <el-button type="text" size="small">查看</el-button>
                        </router-link>
                        <!-- <el-button type="text" size="small" @click="deleteClick(scope.row)"
                            style="color: red">删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,sizes,prev, pager, next,jumper" 
                :total="total" 
                :current-page.sync="current"
                :page-size="pageSize" 
                @current-change="handleCurrentChange"
                :page-sizes="[10, 20, 30, 40,50,100]"
                @size-change="handleSizeChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { wtdwzjinfolist, projectdelete, yzyinfo,exportzjinfolist } from '@/api/index';
export default {
    name: 'dalist',
    data() {
        return {
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_name: '',//创建人 ,
                create_name_id: '',//创建人id ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                czr: '',//承租人 ,
                dabh: '',//档案编号 ,
                dqje: '',//当欠金额 ,
                dqsj: '',//合同到期时间 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                signid: '',//signid ,
                status_code: '1',//1正常 2删除 ,
                type: this.$store.getters.type,//分类 1:房屋 2：楼栋 ,
                update_name: '',//修改人 ,
                update_name_id: '',//修改人id ,
                update_time: '',//修改时间 ,
                ysje: '',//预收金额 ,
                yzj: '',//月租金
                yzy: '',//是否可执行预转已 0：否 1：是 ,
                wtdw:this.$store.getters.company
            },
            tableData: [],
            multipleSelection: [],//预转已选中列表
            yzylist: [{ name: '是', code: '1' }, { name: '否', code: '0' }],
            maxHeight:null
        };
    },
    components: {},
    computed: {
        // 判断变色
        getcolorred(htzt) {
            console.log(htzt);
            return (htzt) => {
                if (htzt == "正常") {
                    return { color: "#19BE6B", fontWeight: 700 };
                } else if (htzt == '已经到期') {
                    return { color: "#D9001B", fontWeight: 700 };
                } else if (htzt == '即将到期') {
                    return { color: "#FF9900", fontWeight: 700 };
                } else if (htzt == '未签合同') {
                    return { color: "#409ee1", fontWeight: 700 };
                }
            };
        },
    },
    methods: {
        //复选框禁用
        selectable(row, rowIndex) {
            //索引是从0开始，条件1是指只有第2行数据不被禁用  
            console.log(row, rowIndex)
            if (row.dyyjje > 0 && row.ysje > 0) {
                return true;  //不禁用
            } else {
                return false;  //禁用
            }
        },
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor(){
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.form.pageSize=this.pageSize
            this.wtdwzjinfolist(this.form);
            console.log(val);
        },
        // 每页条数
        handleSizeChange(val){
            this.current = 1;
            this.pageSize = val;
            this.form.pageSize = val;
            this.wtdwzjinfolist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.wtdwzjinfolist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.pageSize = 10;
            this.form = {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_name: '',//创建人 ,
                create_name_id: '',//创建人id ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                czr: '',//承租人 ,
                dabh: '',//档案编号 ,
                dqje: '',//当欠金额 ,
                dqsj: '',//合同到期时间 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                signid: '',//signid ,
                status_code: '1',//1正常 2删除 ,
                type: this.$store.getters.type,//分类 1:房屋 2：楼栋 ,
                update_name: '',//修改人 ,
                update_name_id: '',//修改人id ,
                update_time: '',//修改时间 ,
                ysje: '',//预收金额 ,
                yzj: '',//月租金
                yzy: '',//是否可执行预转已 0：否 1：是 ,
            };
            this.wtdwzjinfolist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'addproject',
                path: '/addproject'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    projectdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.wtdwzjinfolist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        wtdwzjinfolist(data) {
            wtdwzjinfolist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 预转已接口
        yzyinfo(data) {
            yzyinfo(data).then(res => {
                if (res.code == 200) {
                    this.$message.success('提交成功')
                    this.wtdwzjinfolist(this.form);
                }
            })
        },
        // 预转已点击事件
        yzyclick() {
            let newlist = []
            let data = {
                current: 0,
                pageSize: 0,
                signlist: []
            }
            this.multipleSelection.map(item => {
                newlist.push({ id: item.signid })
            })
            data.signlist = newlist
            this.yzyinfo(data)
            console.log('data', data)
        },
        // 多条预转已点击事件
        handleSelectionChange(val) {
            console.log('val', val)
            this.multipleSelection = val;
        },
        // 是否预转已
        onchangeradio(val) {
            this.wtdwzjinfolist(this.form);
            console.log(this.form.yzy)
        },
        // 导出
        downloadlist() {
            exportzjinfolist(this.form).then(res => {
                console.log(res)
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '租金信息导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res)
            })
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 400
        })
        this.wtdwzjinfolist(this.form);
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 250px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
